package com.example.drools.spring.yc.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.example.drools.spring.yc.constants.StatusTag;
import com.example.drools.spring.yc.entity.YcEnterpriseEntity;
import com.example.drools.spring.yc.service.YcCheckNullService;
import com.example.drools.spring.yc.service.YcUniqueService;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author ddsyw
 * @version 1.0
 * @date 2021/12/28 5:24 下午
 */
@RequestMapping("/yc/test")
@Controller
@Slf4j
public class YcRuleController {

    @Resource
    private YcCheckNullService ycCheckNullService;

    @Resource
    private YcUniqueService ycUniqueService;

    @ResponseBody
    @RequestMapping("/checkNull")
    public String checkNull(@RequestBody List<Map<String, String>> maps) {
        if (CollectionUtil.isEmpty(maps)) {
            return "param is null";
        }
        Map<String, List<Map<String, String>>> map = ycCheckNullService.checkNulls(maps);
        return "success:" + map.get(StatusTag.SUCCESS.getStatus()).size() + "; fail:" + map.get(StatusTag.FAIL.getStatus()).size();
    }


    @ResponseBody
    @RequestMapping("/uniqueCheck")
    public List<YcEnterpriseEntity> uniqueCheck(@RequestBody List<YcEnterpriseEntity> ycEnterpriseEntities) {
        if (CollectionUtil.isEmpty(ycEnterpriseEntities)) {
            return Collections.EMPTY_LIST;
        }
        ycUniqueService.checkUnique(ycEnterpriseEntities, "enterpriseUniqueCheck");
        return ycEnterpriseEntities;
    }
}
